package cn.edu.scau.dormitory_management_system.module.examine.service.impl;

import cn.edu.scau.dormitory_management_system.enums.ApplicationStatusEnum;
import cn.edu.scau.dormitory_management_system.module.examine.dao.CheckinApplicationDao;
import cn.edu.scau.dormitory_management_system.module.examine.entity.CheckinApplicationEntity;
import cn.edu.scau.dormitory_management_system.module.examine.entity.VO.CheckinApplicationVO;
import cn.edu.scau.dormitory_management_system.module.examine.service.CheckinApplicationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Vizzk
 * @description：TODO
 * @date ：2021/8/5 16:57
 */
@Service("checkinApplicationService")
public class CheckinApplicationServiceImpl extends ServiceImpl<CheckinApplicationDao, CheckinApplicationEntity> implements CheckinApplicationService {
    @Override
    public boolean insertCheckinApplication(CheckinApplicationEntity application) {
        return this.baseMapper.insert(application)>0;
    }


    @Override
    public IPage<CheckinApplicationVO> listCheckinApplicationsByUserId(Integer userId, Integer pageNum, Integer pageSize) {
        Page<CheckinApplicationVO> page = new Page<>(pageNum,10);
        IPage<CheckinApplicationVO> pages = this.baseMapper.listCheckinApplicationByUserId(page,userId);
        pages.getRecords().forEach(checkinApplicationVO -> {
            checkinApplicationVO.setStatusDescription(ApplicationStatusEnum.getRemarkByStatus(checkinApplicationVO.getStatus()));
        });
        return pages;
    }


    @Override
    public IPage<CheckinApplicationVO> listCheckinApplications(Integer status, Integer deptId, String name, Integer pageNum, Integer pageSize) {
        Page<CheckinApplicationVO> page = new Page<>(pageNum,pageSize);
        IPage<CheckinApplicationVO> pages = this.baseMapper.listCheckinApplications(page,status,deptId,name);
        pages.getRecords().forEach(checkinApplicationVO -> {
            checkinApplicationVO.setStatusDescription(ApplicationStatusEnum.getRemarkByStatus(checkinApplicationVO.getStatus()));
        });
        return pages;
    }

    @Override
    public boolean retreatApplication(Integer id) {
        return this.baseMapper.retreatApplication(id);
    }
}
